package com.youbug.system.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youbug.system.entity.Card;
import com.youbug.system.service.ICardService;
import com.youbug.system.vo.CardVo;
import com.youbug.common.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 官网卡片存储表 前端控制器
 * </p>
 *
 * @author youbug
 * @since 2023-04-15
 */
@RestController
@RequestMapping("/card")
public class CardController {

    @Autowired
    private ICardService cardService;

    @PostMapping("/getCards")
    public R<IPage<Card>> getAnsmts(@RequestBody CardVo vo){

        IPage<Card> page = cardService.getCardPage(vo);

        return R.ok(page);
    }

    @GetMapping("/getCard/{id}")
    public R<Card> getAnsmt(@PathVariable String id){

        Card card = cardService.getById(id);

        return R.ok(card);
    }

    @PostMapping("/add")
    public R<Boolean> add(@RequestBody Card card){

        boolean save = cardService.save(card);

        return  R.ok(save);
    }

    @GetMapping("/delete/{id}")
    public R<Boolean> delete(@PathVariable String id){

        boolean remove = cardService.removeById(id);

        return  R.ok(remove);
    }

    @PostMapping("/update")
    public R<Boolean> update(@RequestBody Card card){

        boolean save = cardService.updateById(card);

        return  R.ok(save);
    }
}

